<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/limh/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/limh/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/limh/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/limh/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/limh/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/limh/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/limh/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="教程,">










<meta name="description" content="有的时候，我们可能需要多次执行同一块代码。一般情况下，语句是按顺序执行的：函数中的第一个语句先执行，接着是第二个语句，依此类推。 编程语言提供了更为复杂执行路径的多种控制结构。 循环语句允许我们多次执行一个语句或语句组，下面是大多数编程语言中循环语句的流程图：   循环类型C 语言提供了以下几种循环类型。点击链接查看每个类型的细节。    循环类型 描述     while 循环 当给定条件为真">
<meta name="keywords" content="教程">
<meta property="og:type" content="article">
<meta property="og:title" content="C 循环">
<meta property="og:url" content="https://tdnr.gitee.io/limh/2015/01/11/c11/index.html">
<meta property="og:site_name" content="土逗牛肉">
<meta property="og:description" content="有的时候，我们可能需要多次执行同一块代码。一般情况下，语句是按顺序执行的：函数中的第一个语句先执行，接着是第二个语句，依此类推。 编程语言提供了更为复杂执行路径的多种控制结构。 循环语句允许我们多次执行一个语句或语句组，下面是大多数编程语言中循环语句的流程图：   循环类型C 语言提供了以下几种循环类型。点击链接查看每个类型的细节。    循环类型 描述     while 循环 当给定条件为真">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2015/12/loop.png">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2014/09/cpp_while_loop.png">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2014/09/cpp_for_loop.png">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2014/09/cpp_do_while_loop.jpg">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2014/09/A444517D-8D36-483E-919C-916B8A72CB62.jpg">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2014/09/AA7D216C-D0CD-4797-B5E4-4BABC2099830.jpg">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2014/09/6162D669-04C6-4775-924C-EDC75A6FB632.jpg">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2014/09/cpp_break_statement.jpg">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2014/09/cpp_continue_statement.jpg">
<meta property="og:image" content="http://www.runoob.com/wp-content/uploads/2014/09/cpp_goto_statement.jpg">
<meta property="og:updated_time" content="2019-01-18T06:28:35.928Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="C 循环">
<meta name="twitter:description" content="有的时候，我们可能需要多次执行同一块代码。一般情况下，语句是按顺序执行的：函数中的第一个语句先执行，接着是第二个语句，依此类推。 编程语言提供了更为复杂执行路径的多种控制结构。 循环语句允许我们多次执行一个语句或语句组，下面是大多数编程语言中循环语句的流程图：   循环类型C 语言提供了以下几种循环类型。点击链接查看每个类型的细节。    循环类型 描述     while 循环 当给定条件为真">
<meta name="twitter:image" content="http://www.runoob.com/wp-content/uploads/2015/12/loop.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/limh/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://tdnr.gitee.io/limh/2015/01/11/c11/">





  <title>C 循环 | 土逗牛肉</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans ">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/limh/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">土逗牛肉</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/limh/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/limh/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/limh/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/limh/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/limh/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tdnr.gitee.io/limh/limh/2015/01/11/c11/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="土逗牛肉">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/limh/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="土逗牛肉">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">C 循环</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-01-11T20:35:45+08:00">
                2015-01-11
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/limh/categories/C语言教程/" itemprop="url" rel="index">
                    <span itemprop="name">C语言教程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>有的时候，我们可能需要多次执行同一块代码。一般情况下，语句是按顺序执行的：函数中的第一个语句先执行，接着是第二个语句，依此类推。</p>
<p>编程语言提供了更为复杂执行路径的多种控制结构。</p>
<p>循环语句允许我们多次执行一个语句或语句组，下面是大多数编程语言中循环语句的流程图：</p>
<p><img src="http://www.runoob.com/wp-content/uploads/2015/12/loop.png" alt></p>
<hr>
<h4 id="循环类型"><a href="#循环类型" class="headerlink" title="循环类型"></a>循环类型</h4><p>C 语言提供了以下几种循环类型。点击链接查看每个类型的细节。</p>
<table>
<thead>
<tr>
<th>循环类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>while 循环</td>
<td>当给定条件为真时，重复语句或语句组。它会在执行循环主体之前测试条件。</td>
</tr>
<tr>
<td>for 循环</td>
<td>多次执行一个语句序列，简化管理循环变量的代码。</td>
</tr>
<tr>
<td>do…while</td>
<td>循环    除了它是在循环主体结尾测试条件外，其他与 while 语句类似。</td>
</tr>
<tr>
<td>嵌套循环</td>
<td>您可以在 while、for 或 do..while 循环内使用一个或多个循环。</td>
</tr>
</tbody>
</table>
<h5 id="C-while-循环"><a href="#C-while-循环" class="headerlink" title="C while 循环"></a>C while 循环</h5><p>只要给定的条件为真，C 语言中的 while 循环语句会重复执行一个目标语句。</p>
<h6 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h6><p>C 语言中 while 循环的语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">while(condition)</span><br><span class="line">&#123;</span><br><span class="line">   statement(s);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在这里，<strong>statement(s)</strong> 可以是一个单独的语句，也可以是几个语句组成的代码块。</p>
<p><strong>condition</strong> 可以是任意的表达式，当为任意非零值时都为 true。当条件为 true 时执行循环。 当条件为 false 时，退出循环，程序流将继续执行紧接着循环的下一条语句。\</p>
<h6 id="流程图"><a href="#流程图" class="headerlink" title="流程图"></a>流程图</h6><p><img src="http://www.runoob.com/wp-content/uploads/2014/09/cpp_while_loop.png" alt></p>
<p>在这里，while 循环的关键点是循环可能一次都不会执行。当条件为 false 时，会跳过循环主体，直接执行紧接着 while 循环的下一条语句。</p>
<h6 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main ()</span><br><span class="line">&#123;</span><br><span class="line">   /* 局部变量定义 */</span><br><span class="line">   int a = 10;</span><br><span class="line"></span><br><span class="line">   /* while 循环执行 */</span><br><span class="line">   while( a &lt; 20 )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;a 的值： %d\n&quot;, a);</span><br><span class="line">      a++;</span><br><span class="line">   &#125;</span><br><span class="line"> </span><br><span class="line">   return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>a 的值： 10 <br><br>a 的值： 11 <br><br>a 的值： 12 <br><br>a 的值： 13 <br><br>a 的值： 14 <br><br>a 的值： 15 <br><br>a 的值： 16 <br><br>a 的值： 17 <br><br>a 的值： 18 <br><br>a 的值： 19 <br></p>
</blockquote>
<h5 id="C-for-循环"><a href="#C-for-循环" class="headerlink" title="C for 循环"></a>C for 循环</h5><p>for 循环允许您编写一个执行指定次数的循环控制结构。</p>
<h6 id="语法-1"><a href="#语法-1" class="headerlink" title="语法"></a>语法</h6><p>C 语言中 for 循环的语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">for ( init; condition; increment )</span><br><span class="line">&#123;</span><br><span class="line">   statement(s);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>下面是 for 循环的控制流：</p>
<ol>
<li>init 会首先被执行，且只会执行一次。这一步允许您声明并初始化任何循环控制变量。您也可以不在这里写任何语句，只要有一个分号出现即可。</li>
<li>接下来，会判断 condition。如果为真，则执行循环主体。如果为假，则不执行循环主体，且控制流会跳转到紧接着 for 循环的下一条语句。</li>
<li>在执行完 for 循环主体后，控制流会跳回上面的 increment 语句。该语句允许您更新循环控制变量。该语句可以留空，只要在条件后有一个分号出现即可。</li>
<li>条件再次被判断。如果为真，则执行循环，这个过程会不断重复（循环主体，然后增加步值，再然后重新判断条件）。在条件变为假时，for 循环终止。</li>
</ol>
<h6 id="流程图-1"><a href="#流程图-1" class="headerlink" title="流程图"></a>流程图</h6><p><img src="http://www.runoob.com/wp-content/uploads/2014/09/cpp_for_loop.png" alt></p>
<h6 id="实例-1"><a href="#实例-1" class="headerlink" title="实例"></a>实例</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main ()</span><br><span class="line">&#123;</span><br><span class="line">   /* for 循环执行 */</span><br><span class="line">   for( int a = 10; a &lt; 20; a = a + 1 )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;a 的值： %d\n&quot;, a);</span><br><span class="line">   &#125;</span><br><span class="line"> </span><br><span class="line">   return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>a 的值： 10 <br><br>a 的值： 11 <br><br>a 的值： 12 <br><br>a 的值： 13 <br><br>a 的值： 14 <br><br>a 的值： 15 <br><br>a 的值： 16 <br><br>a 的值： 17 <br><br>a 的值： 18 <br><br>a 的值： 19 <br></p>
</blockquote>
<h5 id="C-do…while-循环"><a href="#C-do…while-循环" class="headerlink" title="C do…while 循环"></a>C do…while 循环</h5><p>不像 <strong>for</strong> 和 <strong>while</strong> 循环，它们是在循环头部测试循环条件。在 C 语言中，<strong>do…while</strong> 循环是在循环的尾部检查它的条件。</p>
<p><strong>do…while</strong> 循环与 <strong>while</strong> 循环类似，但是 <strong>do…while</strong> 循环会确保至少执行一次循环。</p>
<h6 id="语法-2"><a href="#语法-2" class="headerlink" title="语法"></a>语法</h6><p>C 语言中 do…while 循环的语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">do</span><br><span class="line">&#123;</span><br><span class="line">   statement(s);</span><br><span class="line"></span><br><span class="line">&#125;while( condition );</span><br></pre></td></tr></table></figure>
<p>请注意，条件表达式出现在循环的尾部，所以循环中的 statement(s) 会在条件被测试之前至少执行一次。</p>
<p>如果条件为真，控制流会跳转回上面的 do，然后重新执行循环中的 statement(s)。这个过程会不断重复，直到给定条件变为假为止。</p>
<h6 id="流程图-2"><a href="#流程图-2" class="headerlink" title="流程图"></a>流程图</h6><p><img src="http://www.runoob.com/wp-content/uploads/2014/09/cpp_do_while_loop.jpg" alt></p>
<h6 id="实例-2"><a href="#实例-2" class="headerlink" title="实例"></a>实例</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main ()</span><br><span class="line">&#123;</span><br><span class="line">   /* 局部变量定义 */</span><br><span class="line">   int a = 10;</span><br><span class="line"></span><br><span class="line">   /* do 循环执行 */</span><br><span class="line">   do</span><br><span class="line">   &#123;</span><br><span class="line">       printf(&quot;a 的值： %d\n&quot;, a);</span><br><span class="line">       a = a + 1;</span><br><span class="line">   &#125;while( a &lt; 20 );</span><br><span class="line"> </span><br><span class="line">   return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>a 的值： 10 <br><br>a 的值： 11 <br><br>a 的值： 12 <br><br>a 的值： 13 <br><br>a 的值： 14 <br><br>a 的值： 15 <br><br>a 的值： 16 <br><br>a 的值： 17 <br><br>a 的值： 18 <br><br>a 的值： 19 <br></p>
</blockquote>
<h5 id="C-嵌套循环"><a href="#C-嵌套循环" class="headerlink" title="C 嵌套循环"></a>C 嵌套循环</h5><p>C 语言允许在一个循环内使用另一个循环，下面演示几个实例来说明这个概念。</p>
<h6 id="语法-3"><a href="#语法-3" class="headerlink" title="语法"></a>语法</h6><p>C 语言中 嵌套 for 循环 语句的语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">for (initialization; condition; increment/decrement)</span><br><span class="line">&#123;</span><br><span class="line">    statement(s);</span><br><span class="line">    for (initialization; condition; increment/decrement)</span><br><span class="line">    &#123;</span><br><span class="line">        statement(s);</span><br><span class="line">        ... ... ...</span><br><span class="line">    &#125;</span><br><span class="line">    ... ... ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h6 id="流程图-3"><a href="#流程图-3" class="headerlink" title="流程图"></a>流程图</h6><p><img src="http://www.runoob.com/wp-content/uploads/2014/09/A444517D-8D36-483E-919C-916B8A72CB62.jpg" alt></p>
<h6 id="C-语言中-嵌套-while-循环-语句的语法："><a href="#C-语言中-嵌套-while-循环-语句的语法：" class="headerlink" title="C 语言中 嵌套 while 循环 语句的语法："></a>C 语言中 嵌套 while 循环 语句的语法：</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">while (condition1)</span><br><span class="line">&#123;</span><br><span class="line">    statement(s);</span><br><span class="line">    while (condition2)</span><br><span class="line">    &#123;</span><br><span class="line">        statement(s);</span><br><span class="line">        ... ... ...</span><br><span class="line">    &#125;</span><br><span class="line">    ... ... ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="http://www.runoob.com/wp-content/uploads/2014/09/AA7D216C-D0CD-4797-B5E4-4BABC2099830.jpg" alt></p>
<h6 id="C-语言中-嵌套-do…while-循环-语句的语法："><a href="#C-语言中-嵌套-do…while-循环-语句的语法：" class="headerlink" title="C 语言中 嵌套 do…while 循环 语句的语法："></a>C 语言中 嵌套 do…while 循环 语句的语法：</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">do</span><br><span class="line">&#123;</span><br><span class="line">    statement(s);</span><br><span class="line">    do</span><br><span class="line">    &#123;</span><br><span class="line">        statement(s);</span><br><span class="line">        ... ... ...</span><br><span class="line">    &#125;while (condition2);</span><br><span class="line">    ... ... ...</span><br><span class="line">&#125;while (condition1);</span><br></pre></td></tr></table></figure>
<p><img src="http://www.runoob.com/wp-content/uploads/2014/09/6162D669-04C6-4775-924C-EDC75A6FB632.jpg" alt></p>
<p>关于嵌套循环有一点值得注意，您可以在任何类型的循环内嵌套其他任何类型的循环。比如，一个 for 循环可以嵌套在一个 while 循环内，反之亦然。</p>
<h6 id="实例-3"><a href="#实例-3" class="headerlink" title="实例"></a>实例</h6><p>下面的程序使用了一个嵌套的 for 循环来查找 2 到 100 中的质数：</p>
<ul>
<li>for 嵌套实例</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main ()</span><br><span class="line">&#123;</span><br><span class="line">   /* 局部变量定义 */</span><br><span class="line">   int i, j;</span><br><span class="line">   </span><br><span class="line">   for(i=2; i&lt;100; i++) &#123;</span><br><span class="line">      for(j=2; j &lt;= (i/j); j++)</span><br><span class="line">        if(!(i%j)) break; // 如果找到，则不是质数</span><br><span class="line">      if(j &gt; (i/j)) printf(&quot;%d 是质数\n&quot;, i);</span><br><span class="line">   &#125;</span><br><span class="line"> </span><br><span class="line">   return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>2 是质数 <br><br>3 是质数 <br><br>5 是质数 <br><br>7 是质数 <br><br>11 是质数 <br><br>13 是质数 <br><br>17 是质数 <br><br>19 是质数 <br><br>23 是质数 <br><br>29 是质数 <br><br>31 是质数 <br><br>37 是质数 <br><br>41 是质数 <br><br>43 是质数 <br><br>47 是质数 <br><br>53 是质数 <br><br>59 是质数 <br><br>61 是质数 <br><br>67 是质数 <br><br>71 是质数 <br><br>73 是质数 <br><br>79 是质数 <br><br>83 是质数 <br><br>89 是质数 <br><br>97 是质数 <br></p>
</blockquote>
<ul>
<li>while 嵌套实例</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">    int i=1,j;</span><br><span class="line">    while (i &lt;= 5)</span><br><span class="line">    &#123;</span><br><span class="line">        j=1;</span><br><span class="line">        while (j &lt;= i )</span><br><span class="line">        &#123;</span><br><span class="line">            printf(&quot;%d &quot;,j);</span><br><span class="line">            j++;</span><br><span class="line">        &#125;</span><br><span class="line">        printf(&quot;\n&quot;);</span><br><span class="line">        i++;</span><br><span class="line">    &#125;</span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>1 <br><br>1 2 <br><br>1 2 3 <br><br>1 2 3 4 <br><br>1 2 3 4 5 <br></p>
</blockquote>
<ul>
<li>do-while 嵌套实例</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">    int i=1,j;</span><br><span class="line">    do</span><br><span class="line">    &#123;</span><br><span class="line">        j=1;</span><br><span class="line">        do</span><br><span class="line">        &#123;</span><br><span class="line">            printf(&quot;*&quot;);</span><br><span class="line">            j++;</span><br><span class="line">        &#125;while(j &lt;= i);</span><br><span class="line">        i++;</span><br><span class="line">        printf(&quot;\n&quot;);</span><br><span class="line">    &#125;while(i &lt;= 5);</span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>&#42; <br><br>&#42;&#42; <br><br>&#42;&#42;&#42; <br><br>&#42;&#42;&#42;&#42; <br><br>&#42;&#42;&#42;&#42;&#42; <br></p>
</blockquote>
<hr>
<h4 id="循环控制语句"><a href="#循环控制语句" class="headerlink" title="循环控制语句"></a>循环控制语句</h4><p>循环控制语句改变你代码的执行顺序。通过它你可以实现代码的跳转。</p>
<p>C 提供了下列的循环控制语句。点击链接查看每个语句的细节。</p>
<table>
<thead>
<tr>
<th>控制语句</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>break 语句</td>
<td>终止循环或 switch 语句，程序流将继续执行紧接着循环或 switch 的下一条语句。</td>
</tr>
<tr>
<td>continue 语句</td>
<td>告诉一个循环体立刻停止本次循环迭代，重新开始下次循环迭代。</td>
</tr>
<tr>
<td>goto 语句</td>
<td>将控制转移到被标记的语句。但是不建议在程序中使用 goto 语句。</td>
</tr>
</tbody>
</table>
<h5 id="C-break-语句"><a href="#C-break-语句" class="headerlink" title="C break 语句"></a>C break 语句</h5><p>C 语言中 break 语句有以下两种用法：</p>
<ol>
<li>当 break 语句出现在一个循环内时，循环会立即终止，且程序流将继续执行紧接着循环的下一条语句。</li>
<li>它可用于终止 switch 语句中的一个 case。</li>
</ol>
<p>如果您使用的是嵌套循环（即一个循环内嵌套另一个循环），break 语句会停止执行最内层的循环，然后开始执行该块之后的下一行代码。</p>
<h6 id="语法-4"><a href="#语法-4" class="headerlink" title="语法"></a>语法</h6><p>C 语言中 break 语句的语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">break;</span><br></pre></td></tr></table></figure>
<h6 id="流程图-4"><a href="#流程图-4" class="headerlink" title="流程图"></a>流程图</h6><p><img src="http://www.runoob.com/wp-content/uploads/2014/09/cpp_break_statement.jpg" alt></p>
<h6 id="实例-4"><a href="#实例-4" class="headerlink" title="实例"></a>实例</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main ()</span><br><span class="line">&#123;</span><br><span class="line">   /* 局部变量定义 */</span><br><span class="line">   int a = 10;</span><br><span class="line"></span><br><span class="line">   /* while 循环执行 */</span><br><span class="line">   while( a &lt; 20 )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;a 的值： %d\n&quot;, a);</span><br><span class="line">      a++;</span><br><span class="line">      if( a &gt; 15)</span><br><span class="line">      &#123;</span><br><span class="line">         /* 使用 break 语句终止循环 */</span><br><span class="line">          break;</span><br><span class="line">      &#125;</span><br><span class="line">   &#125;</span><br><span class="line"> </span><br><span class="line">   return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>a 的值： 10 <br><br>a 的值： 11 <br><br>a 的值： 12 <br><br>a 的值： 13 <br><br>a 的值： 14 <br><br>a 的值： 15 <br></p>
</blockquote>
<h5 id="C-continue-语句"><a href="#C-continue-语句" class="headerlink" title="C continue 语句"></a>C continue 语句</h5><p>C 语言中的 continue 语句有点像 break 语句。但它不是强制终止，continue 会跳过当前循环中的代码，强迫开始下一次循环。</p>
<p>对于 for 循环，continue 语句执行后自增语句仍然会执行。对于 while 和 do…while 循环，continue 语句重新执行条件判断语句。</p>
<h6 id="语法-5"><a href="#语法-5" class="headerlink" title="语法"></a>语法</h6><p>C 语言中 continue 语句的语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">continue;</span><br></pre></td></tr></table></figure>
<h6 id="流程图-5"><a href="#流程图-5" class="headerlink" title="流程图"></a>流程图</h6><p><img src="http://www.runoob.com/wp-content/uploads/2014/09/cpp_continue_statement.jpg" alt></p>
<h6 id="实例-5"><a href="#实例-5" class="headerlink" title="实例"></a>实例</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main ()</span><br><span class="line">&#123;</span><br><span class="line">   /* 局部变量定义 */</span><br><span class="line">   int a = 10;</span><br><span class="line"></span><br><span class="line">   /* do 循环执行 */</span><br><span class="line">   do</span><br><span class="line">   &#123;</span><br><span class="line">      if( a == 15)</span><br><span class="line">      &#123;</span><br><span class="line">         /* 跳过迭代 */</span><br><span class="line">         a = a + 1;</span><br><span class="line">         continue;</span><br><span class="line">      &#125;</span><br><span class="line">      printf(&quot;a 的值： %d\n&quot;, a);</span><br><span class="line">      a++;</span><br><span class="line">     </span><br><span class="line">   &#125;while( a &lt; 20 );</span><br><span class="line"> </span><br><span class="line">   return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>a 的值： 10 <br><br>a 的值： 11 <br><br>a 的值： 12 <br><br>a 的值： 13 <br><br>a 的值： 14 <br><br>a 的值： 16 <br><br>a 的值： 17 <br><br>a 的值： 18 <br><br>a 的值： 19 <br></p>
</blockquote>
<h5 id="C-goto-语句"><a href="#C-goto-语句" class="headerlink" title="C goto 语句"></a>C goto 语句</h5><p>C 语言中的 goto 语句允许把控制无条件转移到同一函数内的被标记的语句。</p>
<p><strong>注意</strong>：在任何编程语言中，都不建议使用 goto 语句。因为它使得程序的控制流难以跟踪，使程序难以理解和难以修改。任何使用 goto 语句的程序可以改写成不需要使用 goto 语句的写法。</p>
<h6 id="语法-6"><a href="#语法-6" class="headerlink" title="语法"></a>语法</h6><p>C 语言中 goto 语句的语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">goto label;</span><br><span class="line">..</span><br><span class="line">.</span><br><span class="line">label: statement;</span><br></pre></td></tr></table></figure>
<p>在这里，label 可以是任何除 C 关键字以外的纯文本，它可以设置在 C 程序中 goto 语句的前面或者后面。</p>
<h6 id="流程图-6"><a href="#流程图-6" class="headerlink" title="流程图"></a>流程图</h6><p><img src="http://www.runoob.com/wp-content/uploads/2014/09/cpp_goto_statement.jpg" alt></p>
<h6 id="实例-6"><a href="#实例-6" class="headerlink" title="实例"></a>实例</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main ()</span><br><span class="line">&#123;</span><br><span class="line">   /* 局部变量定义 */</span><br><span class="line">   int a = 10;</span><br><span class="line"></span><br><span class="line">   /* do 循环执行 */</span><br><span class="line">   LOOP:do</span><br><span class="line">   &#123;</span><br><span class="line">      if( a == 15)</span><br><span class="line">      &#123;</span><br><span class="line">         /* 跳过迭代 */</span><br><span class="line">         a = a + 1;</span><br><span class="line">         goto LOOP;</span><br><span class="line">      &#125;</span><br><span class="line">      printf(&quot;a 的值： %d\n&quot;, a);</span><br><span class="line">      a++;</span><br><span class="line">     </span><br><span class="line">   &#125;while( a &lt; 20 );</span><br><span class="line"> </span><br><span class="line">   return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<blockquote>
<p>a 的值： 10 <br><br>a 的值： 11 <br><br>a 的值： 12 <br><br>a 的值： 13 <br><br>a 的值： 14 <br><br>a 的值： 16 <br><br>a 的值： 17 <br><br>a 的值： 18 <br><br>a 的值： 19 <br></p>
</blockquote>
<hr>
<h4 id="无限循环"><a href="#无限循环" class="headerlink" title="无限循环"></a>无限循环</h4><p>如果条件永远不为假，则循环将变成无限循环。for 循环在传统意义上可用于实现无限循环。由于构成循环的三个表达式中任何一个都不是必需的，您可以将某些条件表达式留空来构成一个无限循环。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;stdio.h&gt;</span><br><span class="line"> </span><br><span class="line">int main ()</span><br><span class="line">&#123;</span><br><span class="line">   for( ; ; )</span><br><span class="line">   &#123;</span><br><span class="line">      printf(&quot;该循环会永远执行下去！\n&quot;);</span><br><span class="line">   &#125;</span><br><span class="line">   return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当条件表达式不存在时，它被假设为真。您也可以设置一个初始值和增量表达式，但是一般情况下，C 程序员偏向于使用 for(;;) 结构来表示一个无限循环。</p>
<p><strong>注意</strong>：您可以按 Ctrl + C 键终止一个无限循环。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/limh/tags/教程/" rel="tag"># 教程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/limh/2015/01/10/c10/" rel="next" title="C 判断">
                <i class="fa fa-chevron-left"></i> C 判断
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/limh/2015/01/12/c12/" rel="prev" title="C 函数">
                C 函数 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/limh/images/avatar.jpg" alt="土逗牛肉">
            
              <p class="site-author-name" itemprop="name">土逗牛肉</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/limh/archives/">
              
                  <span class="site-state-item-count">255</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/limh/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/limh/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/limhGeek" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:1591054297@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/f73b243e7cc9" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-user-circle-o"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#循环类型"><span class="nav-number">1.</span> <span class="nav-text">循环类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#C-while-循环"><span class="nav-number">1.1.</span> <span class="nav-text">C while 循环</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#语法"><span class="nav-number">1.1.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#流程图"><span class="nav-number">1.1.2.</span> <span class="nav-text">流程图</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#实例"><span class="nav-number">1.1.3.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#C-for-循环"><span class="nav-number">1.2.</span> <span class="nav-text">C for 循环</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#语法-1"><span class="nav-number">1.2.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#流程图-1"><span class="nav-number">1.2.2.</span> <span class="nav-text">流程图</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#实例-1"><span class="nav-number">1.2.3.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#C-do…while-循环"><span class="nav-number">1.3.</span> <span class="nav-text">C do…while 循环</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#语法-2"><span class="nav-number">1.3.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#流程图-2"><span class="nav-number">1.3.2.</span> <span class="nav-text">流程图</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#实例-2"><span class="nav-number">1.3.3.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#C-嵌套循环"><span class="nav-number">1.4.</span> <span class="nav-text">C 嵌套循环</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#语法-3"><span class="nav-number">1.4.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#流程图-3"><span class="nav-number">1.4.2.</span> <span class="nav-text">流程图</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#C-语言中-嵌套-while-循环-语句的语法："><span class="nav-number">1.4.3.</span> <span class="nav-text">C 语言中 嵌套 while 循环 语句的语法：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#C-语言中-嵌套-do…while-循环-语句的语法："><span class="nav-number">1.4.4.</span> <span class="nav-text">C 语言中 嵌套 do…while 循环 语句的语法：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#实例-3"><span class="nav-number">1.4.5.</span> <span class="nav-text">实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#循环控制语句"><span class="nav-number">2.</span> <span class="nav-text">循环控制语句</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#C-break-语句"><span class="nav-number">2.1.</span> <span class="nav-text">C break 语句</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#语法-4"><span class="nav-number">2.1.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#流程图-4"><span class="nav-number">2.1.2.</span> <span class="nav-text">流程图</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#实例-4"><span class="nav-number">2.1.3.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#C-continue-语句"><span class="nav-number">2.2.</span> <span class="nav-text">C continue 语句</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#语法-5"><span class="nav-number">2.2.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#流程图-5"><span class="nav-number">2.2.2.</span> <span class="nav-text">流程图</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#实例-5"><span class="nav-number">2.2.3.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#C-goto-语句"><span class="nav-number">2.3.</span> <span class="nav-text">C goto 语句</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#语法-6"><span class="nav-number">2.3.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#流程图-6"><span class="nav-number">2.3.2.</span> <span class="nav-text">流程图</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#实例-6"><span class="nav-number">2.3.3.</span> <span class="nav-text">实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#无限循环"><span class="nav-number">3.</span> <span class="nav-text">无限循环</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">土逗牛肉</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
	var str = GetUrlParam('height');
    if (str === '0'){
		document.getElementById('header').style.display = 'none';
		document.getElementById('comments').style.display = 'none';
		document.getElementById('footer').style.display = 'none';
		document.getElementsByClassName('post-footer').item(0).style.display = 'none'
	}
	
    function GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split("&");
            var arr;

            for (var i = 0; i < arrPara.length; i++) {
                 arr = arrPara[i].split("=");

                if (arr != null && arr[0] === paraName) {
                    return arr[1];
                }
            }
            return "";
        } else {
            return "";
        }
    }
</script>









  












  
  
    <script type="text/javascript" src="/limh/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/limh/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/limh/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/limh/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/limh/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/limh/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
